import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'
import './index.less'
import WriteBox from '../../components/WriteBox';
import api from '../../service/api';

export default class AskQuestion extends Taro.Component {

  config = {
    navigationBarTitleText: '写问题'
  }

  constructor() {
    super(...arguments)
    this.state = {
      nowCount: '',
      doctorInfo:'',
      sendQuestionCount:1
    }
  }

  componentDidShow = () =>{
    this.showCout()
  }

  showCout = () => {
    let params = {}
    params.userId = Taro.getStorageSync('loginInfo').userId
    api.get('/inquiry/find/currentCount',params).then(res=>{
      this.setState({
        nowCount:res.data.data.nowCount
      })
    })
  }

  buyNumber = () => {
    Taro.navigateTo({
      url:'/pages/payment/index?paystatus=1'
    })
  }

  render() {

    return (
      <View className='page'>
        <View className='page-top'>
          <View className='page-top-headPhoto'>
            <Image className='page-top-Image' src={this.$router.params.headImage}></Image>
          </View>
          <View className='page-top-headName'>
            <View className='page-top-name'>
              {this.$router.params.name}
              <Text className='page-top-subName'>{this.$router.params.department}</Text>
            </View>
            <View className='page-top-hospital'>
              {this.$router.params.hospital}
            </View>
          </View>
        </View>
        <View className='page-main'>

         <WriteBox sendUserId={this.$router.params.doctorId} sendQuestionCount={this.state.sendQuestionCount}></WriteBox>

         <View className='page-bottom-tips'>
            问诊次数剩余<Text className='page-bottom-tips-color'>{this.state.nowCount}</Text>次
            {
              this.state.nowCount <= 0 &&
              <Text className='page-bottom-tips-number' onClick={this.buyNumber.bind(this)}>购买次数 ></Text>
            }
          </View>
        </View>

        <View className='page-bottom'></View>
      </View>
    )
  }
}
